<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input
        type="text"
        placeholder="enter the name you search"
      />&nbsp;<button @click="queryUserListHandle">Search</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";
import PubSub from "pubsub-js";

export default {
  name: "Header",
  methods: {
    async queryUserListHandle() {
      /* 发布 */
      PubSub.publish("setState", { isInit: false, isSearch: true });
      const {
        data: { items },
      } = await axios.get(
        `https://api.github.com/search/users?q=${this.searchKey}`
      );
      PubSub.publish("setState", { isSearch: false, userList: items });
    },
  },
};
</script>

<style>
</style>